package cc.example.photoselctor;

import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import cc.fostion.photoselector.activity.EditorActivity;
import cc.fostion.photoselector.PhotoSelector;

public class DemoActivity extends AppCompatActivity {

    ImageView image;
    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);

        image = (ImageView)findViewById(R.id.image);
        btn = (Button)findViewById(R.id.btn);


        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PhotoSelector.gotoSelector(DemoActivity.this);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(resultCode == RESULT_OK && requestCode == EditorActivity.FLAG_REQUEST_CROP){
            Bitmap bitmap = data.getParcelableExtra("bitmap");
            if(bitmap != null){
                image.setImageBitmap(bitmap);
            }
        }
    }
}
